package com.example.controller;


import com.example.entity.Homework;
import com.example.entity.Login;
import com.example.entity.Script;
import com.example.entity.Storyboardfiles;
import com.example.mapper.HomeworkMapper;
import com.example.result.Result;
import com.example.service.IHomeworkService;
import com.example.service.IScriptService;
import com.example.service.IStoryboardfilesService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;

import static java.lang.Character.getType;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 陈昌吉
 * @since 2024-04-16
 */

@ResponseBody
@CrossOrigin
@Data
@Slf4j
@RestController
@RequestMapping("/homework")
public class HomeworkController {

    @Autowired
    private IHomeworkService iHomeworkService;
    @Autowired
    private IScriptService iScriptService;
    @Autowired
    private HomeworkMapper homeworkMapper;


    @Autowired
    private IStoryboardfilesService storyboardfilesService;
    /**
     * 剧本模块获取所有作业
     * @return
     */
    @GetMapping("/getHomeWork")
    public Result<List<Homework>> getHomeWork(){
        List<Homework> homework=iHomeworkService.getHomeWork();
        return Result.success(homework);
    }

    /**
     * 获取Sript作业状态
     */
    @PostMapping("/getState")
    public Result getState(@RequestBody ArrayList<Integer> hids){
    log.info("作业hids为{},",hids);
        LinkedHashSet<Script> scriptState = iScriptService.getScriptState(hids);
        return Result.success(scriptState);
    }

    @PostMapping("/getStoryState")
    public Result getStoryState(@RequestBody ArrayList<Integer> hids){
        log.info("作业hids为{},",hids);
        LinkedHashSet<Storyboardfiles> storyState = storyboardfilesService.getStoryState(hids);
        return Result.success(storyState);
    }

    //新增及修改
    @PostMapping("/addHomework")
    public Result<Homework> addlogin(@RequestBody Homework homework){
        System.out.println(homework);
        System.out.println(homework.getHid());
        if (homework.getHid()==0){
            iHomeworkService.addHomework(homework);
        }else {
            homeworkMapper.updateById(homework);
        }
        return Result.success();
    }
    //删除
    @PostMapping("/deleteHomework")
    public Result deleteHomework(@RequestBody Integer hid){
        log.info("删除的id为{}，",hid);
        int i = homeworkMapper.deleteById(hid);
        return  Result.success(i);
    }
}


